package com.xgk.boot.module.core.controller.admin.price;

import com.xgk.boot.framework.common.pojo.CommonResult;
import com.xgk.boot.framework.common.pojo.PageResult;
import com.xgk.boot.framework.common.util.object.BeanUtils;
import com.xgk.boot.module.core.controller.admin.price.vo.LgExtrasDictReqVO;
import com.xgk.boot.module.core.controller.admin.price.vo.LgExtrasDictSaveVO;
import com.xgk.boot.module.core.controller.admin.price.vo.LgExtrasDictVO;
import com.xgk.boot.module.core.dal.entity.price.LgExtrasDictDO;
import com.xgk.boot.module.core.service.price.LgExtrasDictServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.xgk.boot.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 物流杂费字典")
@RestController("adminLgExtrasDictController")
@RequestMapping("/system/extras")
public class LgExtrasDictController {

    @Resource
    private LgExtrasDictServiceImpl lgExtrasDictService;

    @PostMapping("/create")
    @Operation(summary = "创建杂费项")
    @PreAuthorize("@ss.hasPermission('system:admin')")
    public CommonResult<Boolean> createLgExtrasDict(@Valid @RequestBody LgExtrasDictSaveVO createReqVO) {
        return success(lgExtrasDictService.addLgExtrasDict(createReqVO));
    }

    @PutMapping("/update/{id}")
    @Operation(summary = "修改杂费项")
    @Parameter(name = "id", description = "杂费项id", required = true, example = "1934923143484133377")
    @PreAuthorize("@ss.hasPermission('system:admin')")
    public CommonResult<Boolean> updateXxx(@PathVariable("id") Long id,@Valid @RequestBody LgExtrasDictSaveVO updateReqVO) {
        return success(lgExtrasDictService.updateLgExtrasDict(updateReqVO));
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除杂费项")
    @Parameter(name = "id", description = "杂费项id", required= true, example = "1024")
    @PreAuthorize("@ss.hasPermission('system:admin')")
    public CommonResult<Boolean> deleteLgExtrasDict(@PathVariable("id") Long id) {
        return success(lgExtrasDictService.deleteLgExtrasDictById(id));
    }


    @GetMapping("/get/{id}")
    @Operation(summary = "获取杂费项信息")
    @Parameter(name = "id", description = "杂费项id", required = true, example = "1934923143484133377")
    @PreAuthorize("@ss.hasPermission('system:admin')")
    public CommonResult<LgExtrasDictVO> getLgExtrasDictById(@PathVariable("id") Long id) {
        return success(lgExtrasDictService.getLgExtrasDictById(id));
    }

    @PostMapping("/page_list")
    @Operation(summary = "分页获得杂费项列表")
    @PreAuthorize("@ss.hasPermission('system:admin')")
    public CommonResult<PageResult<LgExtrasDictVO>> pageListLgExtrasDicts(@Valid @RequestBody LgExtrasDictReqVO pageReqVO) {
        PageResult<LgExtrasDictDO> customerDOPageResult = lgExtrasDictService.pageList(pageReqVO);
        PageResult<LgExtrasDictVO> bean = BeanUtils.toBean(customerDOPageResult, LgExtrasDictVO.class);
        return CommonResult.success(bean);
    }

    @PostMapping("/list")
    @Operation(summary = "获得杂费项列表")
    @PreAuthorize("@ss.hasPermission('system:admin')")
    public CommonResult<List<LgExtrasDictVO>> listLgExtrasDicts(@Valid @RequestBody LgExtrasDictReqVO pageReqVO) {
        List<LgExtrasDictDO> listLgExtrasDicts = lgExtrasDictService.getListLgExtrasDicts(pageReqVO);
        List<LgExtrasDictVO> bean = BeanUtils.toBean(listLgExtrasDicts, LgExtrasDictVO.class);
        return CommonResult.success(bean);
    }

}
